#ifndef ACCELERATETRANSFER_H
#define ACCELERATETRANSFER_H

struct GLFWwindow;
class Shader;
class AccelerateTransfer
{
public:
    enum YUVCHANNEL{Y=0,U,V};
    enum RGBCHANNEL{R=0,G,B};
    static bool opengl_init(int major_version=3, int minor_version=3,bool windowVisable=false);

    AccelerateTransfer();
    ~AccelerateTransfer();

    bool transfer_init(int winW,int winH,const char* title="default");
    void prepare_context(int input_w, int input_h, int pixelBytes = 1, float scalew = 1.0, float scaleh = 1.0);
    void update_texture(YUVCHANNEL channel_yuv,const unsigned char* data);
    void draw_once();
    int read_pixel_channel(RGBCHANNEL channel_rgb, const int planesize, int& w,int& h, unsigned char* plane);
    int read_pixel_rgb(const int planesize, int& w,int& h, unsigned char* plane);
public:
    unsigned char* ydata=0;
    unsigned char* udata=0;
    unsigned char* vdata=0;
private:
    int win_width, win_height;
    int readPixelSize=1;
    unsigned int readPixelType=0x1401;

    Shader* shd=0;
    GLFWwindow* window=0;
private:
    unsigned int VBO, VAO, EBO;
    unsigned int PBOS[6];
    unsigned int rgbpbos[2];
    int pboGroupIdxCur = 0;
    int pboGroupIdxNext = 1;
    unsigned int FBO;
    unsigned int texColorBuffer;
    struct TextureInfo{
        unsigned int textureId;
        unsigned int pixelFormatCode;//GL_RED
        unsigned int pixelTypeCode;//GL_UNSIGNED_BYTE
        int textureH,textureW;
    };
    TextureInfo tf[3];
};

#endif // ACCELERATETRANSFER_H
